/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package molehillempirecalculator.utils;

import javax.swing.table.AbstractTableModel;

/**
 *
 * @author Praiet
 */
public class MyTableModel extends AbstractTableModel {

    public String[] header;
    public Object[][] data;

    public MyTableModel(String[] header, Object[][] data) {
        this.header = new String[header.length];
        for (int i = 0; i < header.length; i++) {
            this.header[i] = header[i];
        }

        this.data = new Object[data.length][header.length];
        for (int i = 0; i < data.length; i++) {
            for (int j = 0; j < data[i].length; j++) {
                this.data[i][j] = data[i][j];
            }
        }
    }

    public int getRowCount() {
        return data.length;
    }

    @Override
    public String getColumnName(int col) {
        return header[col];
    }

    public int getColumnCount() {
        return header.length;
    }

    public Object getValueAt(int rowIndex, int columnIndex) {
        return data[rowIndex][columnIndex];
    }

    @Override
    public Class getColumnClass(int c) {
        return getValueAt(0, c).getClass();
    }

    @Override
    public void setValueAt(Object value, int row, int col) {
        data[row][col] = value;
        fireTableCellUpdated(row, col);
    }
}